import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home";
import AddOil from "../views/Home/components/AddOil";
import CarLife from "../views/Home/components/CarLife";
import Mine from "../views/Home/components/Mine";
import Detail from "../views/ItemDetail";
import OrderList from "../views/OrderList";
import OrderDetail from "../views/OrderDetail";
import Coupon from "../views/Coupon";
import Login from "../views/Login";

Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    name: "Login",
    component: Login
  },
  {
    path: "/",
    name: "Home",
    component: Home,
    redirect: "/login",
    children: [
      {
        path: "add_oil",
        name: "AddOil",
        component: AddOil
      },
      {
        path: "car_life",
        name: "CarLife",
        component: CarLife
      },
      {
        path: "mine",
        name: "Mine",
        component: Mine,
        beforeEnter(to, from, next) {
          if (from.name === null) {
            next({ name: "AddOil" });
          } else {
            next();
          }
        }
      }
    ]
  },
  {
    path: "/detail",
    name: "Detail",
    component: Detail
  },
  {
    path: "/order",
    name: "OrderList",
    component: OrderList
  },
  {
    path: "/order_detail",
    name: "OrderDetail",
    component: OrderDetail
  },
  {
    path: "/coupon",
    name: "Coupon",
    component: Coupon
  }
];

const router = new VueRouter({
  routes
});

export default router;
